<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
        <title>学生管理</title>
        <include file='Layout:ins_css' />
        <style type="text/css">
            #addBtn {
                float: right;
                margin: -7px -6px 9px;
            }
            #addClassBtn{
                float: left;
            }
            #checkStuBtn{

            }
        </style>
    </head>
    <body>
        <div class="wrapper wrapper-content animated fadeInRight">
            <div class="row">
                <div class="col-sm-12">
                    <div class="ibox float-e-margins">
                        <div class="ibox-title">
                            <h5>学生管理</h5>
                            <a id="addBtn" href="javascript:void(0);" class="btn btn-primary">添加学生</a>
                        </div>
                        <div class="row s-row">
                            <div class="col-sm-12">
                                <div class="price-div">
                                    <form class="form-horizontal">
                                        <div class="form-group cyf-form-group">
                                            <div class="col-sm-4" style="margin-top: 10px; margin-bottom: 10px">
                                                <label style="float: left" class="col-sm-4 control-label cvbnm">授课班: </label>
                                                <select class="form-control col-sm-" id="teaching_class_id" name="teaching_class_id" style="min-height: 35px">
                                                    <option value="0">全部</option>
                                                    <volist name="tc_info" id="vo">
                                                        <option value="{$vo.tc_id}">{$vo.tc_name}</option>
                                                    </volist>
                                                </select>
                                            </div>
                                        </div>
                                        <div class="form-group cyf-form-group">
                                            <if condition="$role_id eq 2">
                                                <div class="col-sm-1" style="margin-top: 10px; margin-bottom: 10px; float: left">
                                                    <a id="checkStuBtn" href="javascript:void(0);" class="btn btn-info">审核通过</a>
                                                </div>
                                            </if>
                                            <div class="col-sm-1" style="margin-top: 10px; margin-bottom: 10px; float: left">
                                                <!--<button class="btn btn-success" id="addClassBtn">添加教学班</button>-->
                                                <a id="addClassBtn" href="javascript:void(0);" class="btn btn-success">添加教学班</a>
                                            </div>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                        <div class="ibox-content">
                            <table class="table table-striped table-bordered table-hover dataTables-example" id="RuleTable">
                                <thead>
                                <tr>
                                    <th width="4%"> <input type="checkbox" id="checkall"></th>
                                    <th width="12%">学号</th>
                                    <th width="12%">姓名</th>
                                    <th width="12%">性别</th>
                                    <th width="12%">教学班</th>
                                    <th width="12%">专业</th>
                                    <th width="12%">状态</th>
                                    <th width="12%">操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <include file='Layout:ins_js' />
        <script type="text/javascript">
            $(document).ready(function () {check_index();
                //自检
                check_index();
                //datatable
                sTable = $(".table").DataTable({
                    "fnServerParams": function(aoData) {
                        aoData.push({
                            'name': 'tc_id',
                            'value': $('select#teaching_class_id option:selected').val()
                        });
                    },
                    "bAutoWidth":false,
                    "oLanguage": {
                        "sLengthMenu": "每页 _MENU_ ",
                        "sProcessing": "处理中...",
                        "sZeroRecords": "没有匹配结果",
                        "sInfo": "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
                        "sInfoEmpty": "显示第 0 至 0 项结果，共 0 项",
                        "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
                        "sInfoPostFix": "",
                        "sSearch": "搜索:",
                        "sUrl": "",
                        "sEmptyTable": "表中数据为空",
                        "sLoadingRecords": "载入中...",
                        "sInfoThousands": ",",
                        "oPaginate": {
                            "sFirst": "首页",
                            "sPrevious": "上页",
                            "sNext": "下页",
                            "sLast": "末页"
                        },
                        "oAria": {
                            "sSortAscending": ": 以升序排列此列",
                            "sSortDescending": ": 以降序排列此列"
                        }
                    },
                    'columnDefs':[{
                        orderable: false,
                        className: 'select-checkbox',
                        targets:   0
                    }],
                    select: {
                        style:    'os',
                        selector: 'td:first-child'
                    },
                    "sAjaxSource": "__URL__/class_student_manage_ShowDatatables", //调用php后台接口方法地址   //class_manage_ShowDatatables
                    "aoColumns": [{
                        "data": null,
                        orderable: false,
                        render: function(data, type, row, meta){
                            // var dat = {"stu_id":data.stu_id,"tc_id":data.tc_id};
                            var dat = data.stu_id + ',' + data.tc_id;
                            return '<input type="checkbox" name="checkBox" class="checkchild" value=" ' + dat +  '" > ';
                        }
                    },{
                        'data': 'stu_id'
                    },{
                        'data': 'stu_name'
                    },{
                        'data': 'stu_sex'
                    },{
                        'data': 'tc_name'
                    },{
                        'data': 'pro_name'
                    },{
                        'data': 'stu_tc_status'
                    }, {
                        "data": null,
                        orderable: false,
                        render: function(data, type, row, meta) {
                            return '<a type="button" class="btn btn-success" href="#" onclick=editFromID(this) >编辑</a>|<a type="button" class="btn btn-danger" href="#" onclick=delFromID(this) >删除</a>'
                        }
                    }]
                });
            });
            $('#checkall').on('click',function(){
                var check = $(this).prop("checked");
                // $('.checkchild').prop('checked',check);
                sTable.$('.checkchild').prop('checked',check);
            });
            $("select#teaching_class_id").change(function(){
                //console.log($('select#class_id option:selected').val())
                sTable.ajax.reload();
            });
            $('#checkStuBtn').on('click',function () {
                var checkedBox = sTable.$("input[name='checkBox']:checked");
                var chk_value = [];
                if (checkedBox.length == 0) {
                    toastr.warning("请先选择绑定的记录！");
                    return;
                }else {
                    sTable.$('input[name="checkBox"]:checked').each(function () {
                        chk_value.push($(this).val().trim());
                    });
                    $.ajax({
                        type: "post",
                        url: "__URL__/check_TcStudent",
                        async: true,
                        data: {
                            'check_value' : chk_value
                        },
                        dataType: 'json',
                        success: function(p) {
                            if(p.state) {
                                toastr.success(p.info);
                                sTable.ajax.reload();
                            } else {
                                toastr.warning(p.info);
                            }
                            sil_reloading();
                        }
                    });
                }
            });
            //添加教学班点击事件
            $('#addClassBtn').on('click',function () {
                var tec_id =  $('select#teaching_class_id option:selected').val();
                if (tec_id === '0' || tec_id == null){
                    toastr.warning("请选择授课班");
                    return;
                }
                var tec_name = $('select#teaching_class_id option:selected').text();
                window.location.href = '__URL__/add_class?tec_name=' + tec_name;
            });
            $('#addBtn').on('click',function () {
                var tec_id =  $('select#teaching_class_id option:selected').val();
                if (tec_id === '0' || tec_id == null){
                    toastr.warning("请选择授课班");
                    return;
                }
                var tec_name = $('select#teaching_class_id option:selected').text();
                window.location.href = '__URL__/add_class_student?tec_name=' + tec_name;
            });
        </script>
    </body>
</html>